require 'rss/2.0'
require 'open-uri'

class RssPostReader

  def self.parse_url (url, length)
    feed_url = url;
		posts = []
    open(feed_url) do |http|
      response = http.read
      result = RSS::Parser.parse(response, false)
      result.items.each_with_index do |item, i|
        posts << RssPost.new(item.link, item.title, item.date, item.description) if ++i < length
      end 

    end
    return posts
  end

end

class RssPost
	attr_accessor :link, :content, :title, :date

	def initialize(link, title, date, content)
		@link = link
		@content = content
		@title = title
		@date = date
	end
end

